#include "rclcpp/rclcpp.hpp"
#include "std_msgs/msg/string.hpp"
#include "topic_pub.hpp"

using namespace std::chrono_literals;

namespace pub_topic
{
   
   topic_pub::topic_pub(std::string name) : Node(name)
   {
        RCLCPP_INFO(this->get_logger(),"topic_pub");
        pub_ = this->create_publisher<std_msgs::msg::String>("/topic_pub_sub",10);
        timer_ = this->create_wall_timer(500ms,std::bind(&topic_pub::timer_cb,this));
   }
   
   topic_pub::~topic_pub()
   {

   }

   void topic_pub::timer_cb()
    {
        auto message = std_msgs::msg::String();
        message.data = "This is topic pub";
        RCLCPP_INFO(this->get_logger(),message.data.c_str());
        pub_->publish(message);
    }
} // namespace pub_topic


int main(int argc, char **argv)
{
    rclcpp::init(argc,argv);
    auto node = std::make_shared<pub_topic::topic_pub>("topic_pub");
    rclcpp::spin(node);
    rclcpp::shutdown();
    return 0;
}
